package com.fuershiye.woman.monitor.controller;

import com.fuershiye.woman.monitor.beans.Result;
import com.fuershiye.woman.monitor.constants.Massage;
import com.fuershiye.woman.monitor.model.Department;
import com.fuershiye.woman.monitor.service.DepartmentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 部门的管理
 * 
 * @author yongyongdong
 *
 */
@Controller
@RequestMapping(value = "/department/query")
@SuppressWarnings("unchecked")
public class DepartmentQueryController {

	private static final Logger logger = LoggerFactory
			.getLogger(DepartmentQueryController.class);

	@Autowired
	DepartmentService departmentService;


	//根据地级市id，获取下属区县列表信息
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(value = "/county.do")
	@ResponseBody
	public Result getCounty(Long areaid) {

		if(areaid==null||areaid==0){
			return new Result(Massage.ERROR_PARAMETER );
		}

		//部门级别 1:国家级;2:省/部级;3:地级市;4:区县级;5:乡镇级;6:其他
		Integer level = 4;

		return new Result(Massage.SUCCESS, departmentService.getAllByLevelAndArea(level, areaid, 1));
	}


	//获取省级部门的ID,名称,简称
	@SuppressWarnings({ "rawtypes", "unchecked" })
//	@RequiresPermissions("department:province")
	@RequestMapping(value = "/province.do")
	@ResponseBody
	public Result getProvince() {

		//部门级别 1:国家级;2:省/部级;3:地级市;4:区县级;5:乡镇级;6:其他
		Integer level = 2;
		return new Result(Massage.SUCCESS, departmentService.getAllSnames(level, null, 1));
		
	}
	
	//获取某一地级市，下所有单位的ID,名称,简称
	@SuppressWarnings({ "rawtypes", "unchecked" })
//	@RequiresPermissions("department:sameArea")
	@RequestMapping(value = "/city.do")
	@ResponseBody
	public Result getSameArea(Long areaid) {

		//部门级别 1:国家级;2:省/部级;3:地级市;4:区县级;5:乡镇级;6:其他
		Integer level = 3;

		return new Result(Massage.SUCCESS, departmentService.getAllByLevelAndArea(level, areaid, 1));
	}

	//	@RequiresPermissions("department:samePid")
	@RequestMapping(value = "/samePid.do")
	@ResponseBody
	public Result getSamePidById(Long departid) {

		if(departid==null||departid==0){
			return new Result(Massage.ERROR_PARAMETER );
		}

		Department department = departmentService.get(departid);
		if(department==null){
			return new Result(Massage.DEPART_IS_NULL );
		}

		return new Result(Massage.SUCCESS, departmentService.listByPidOrArea(department.getPid(), null));
	}

}
